package com.kin207.netty.handle.impl;

import com.kin207.netty.context.RequestContext;
import com.kin207.netty.handle.IMessageHandle;
import com.kin207.netty.msg.vo.P2pMessageReqVo;
import com.kin207.netty.msg.vo.P2pMessageVo;
import com.kin207.netty.session.Session;
import com.kin207.netty.session.SessionManagerAbs;

public class P2pMessageHandle implements IMessageHandle<P2pMessageReqVo> {

	public String name() {
		return "/msg/p2p";
	}

	public Class paramClass() {
		return P2pMessageReqVo.class;
	}

	public void handle(P2pMessageReqVo param) {
		RequestContext req = RequestContext.curr.get();
		Session session = req.getSession();
		SessionManagerAbs sessionManger = req.getSessionManager();
		
		String name = param.getName();
		
		P2pMessageVo msg = new P2pMessageVo(session.getName(), param.getMessage());
		if(sessionManger.sendMessageForName(param.getName(), msg.toString(),System.currentTimeMillis())!=0){
			req.wirte(String.format("error:%s不在线,消息未送达", name));
		}
	}

}
